﻿// -----------------------------------------------------------------------
// <copyright file="PrimitiveTypeConverter.cs" company="none">
// Copyright (c) 2012 M. Alberti, xanatos(at)live.it
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
// </copyright>
// -----------------------------------------------------------------------

namespace FluentSerializer.Utilities
{
    using System;
    using System.Runtime.InteropServices;

    /// <summary>
    /// A little hack to quicly access the bytes of a type, or to compose a type
    /// from its bytes.
    /// </summary>
    [StructLayout(LayoutKind.Explicit)]
    public struct PrimitiveTypeConverter
    {
        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public byte ByteA;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(1)]
        public byte ByteB;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(2)]
        public byte ByteC;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(3)]
        public byte ByteD;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(4)]
        public byte ByteE;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(5)]
        public byte ByteF;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(6)]
        public byte ByteG;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(7)]
        public byte ByteH;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public sbyte SByteA;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(1)]
        public sbyte SByteB;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(2)]
        public sbyte SByteC;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(3)]
        public sbyte SByteD;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(4)]
        public sbyte SByteE;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(5)]
        public sbyte SByteF;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(6)]
        public sbyte SByteG;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(7)]
        public sbyte SByteH;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public bool BoolA;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(1)]
        public bool BoolB;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(2)]
        public bool BoolC;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(3)]
        public bool BoolD;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(4)]
        public bool BoolE;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(5)]
        public bool BoolF;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(6)]
        public bool BoolG;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(7)]
        public bool BoolH;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public short Int16A;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(2)]
        public short Int16B;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(4)]
        public short Int16C;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(6)]
        public short Int16D;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public ushort UInt16A;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(2)]
        public ushort UInt16B;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(4)]
        public ushort UInt16C;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(6)]
        public ushort UInt16D;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public char CharA;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(2)]
        public char CharB;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(4)]
        public char CharC;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(6)]
        public char CharD;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public int Int32A;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(4)]
        public int Int32B;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public uint UInt32A;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(4)]
        public uint UInt32B;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public long Int64;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public ulong UInt64;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public float Single;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public double Double;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public IntPtr IntPtr;

        /// <summary>
        /// 
        /// </summary>
        [FieldOffset(0)]
        public UIntPtr UIntPtr;
    }
}